package com.company.gas.controller;


import com.company.gas.pojo.GasBase;
import com.company.gas.service.IGasBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/GasBase")
@Api(tags = "燃气库管理相关接口")
public class GasBaseController {
    @Autowired
    private IGasBaseService iGasBaseService;


    //查询全部燃气库
    @GetMapping("/queryGasBaseList")
    @ApiOperation("查询全部燃气库")
    public List<GasBase> queryGasBaseList(){
        List<GasBase> gasBaseList = iGasBaseService.queryGasBaseList();
        for (GasBase gasBase : gasBaseList) {
            System.out.println(gasBase);
        }
        return gasBaseList;
    }
    //按ID查询燃气库
    @GetMapping("/queryGasBaseByID")
    @ApiOperation("根据baseId查询指定设备")
    public GasBase queryGasBaseByID(@RequestParam(value = "设备ID") String baseId){
        GasBase gasBase = iGasBaseService.queryGasBaseByID(baseId);
        System.out.println(gasBase);
        return gasBase;
    }
    //增加燃气库
    @GetMapping("/addGasBase")
    @ApiOperation("添加一个设备")
    public String addGasBase(@RequestParam(value = "燃气库ID") String baseId,@RequestParam(value = "燃气储量") BigDecimal gasStore,
                             @RequestParam(value = "燃气库地址") String baseAdr,@RequestParam(value = "标识符") Boolean flag,
                             @RequestParam(value = "创建者") String createBy,@RequestParam(value = "修改者") String modifyBy){
        int isaddGasBase = iGasBaseService.addGasBase(baseId, gasStore, baseAdr, flag, createBy, modifyBy);
        if(isaddGasBase == 1){
            return "add success";
        }else{
            return  "failed";
        }
    }
    //删除燃气库
    @GetMapping("/deleteGasBaseByID")
    @ApiOperation("根据baseId删除指定燃气库")
    public String deleteGasBaseByID(@RequestParam(value = "燃气库ID") String baseId){
        int isdeleteGasBaseByID = iGasBaseService.deleteGasBaseByID(baseId);
        if (isdeleteGasBaseByID == 1){
            return "delete success";
        }else {
            return "failed";
        }
    }
    //修改燃气库
    @GetMapping("/updateGasBase")
    @ApiOperation("修改一个燃气库")
    public String updateGasBase(@RequestParam(value = "燃气库ID") String baseId,@RequestParam(value = "燃气储量") BigDecimal gasStore,
                                @RequestParam(value = "燃气库地址") String baseAdr,@RequestParam(value = "修改者") String modifyBy){
        int isupdateGasBase = iGasBaseService.updateGasBase(baseId,gasStore,baseAdr,modifyBy);
        if (isupdateGasBase == 1){
            return "update success";
        }else {
            return "failed";
        }
    }

}
